<template>
  <div class="dashboard-container">
    <div class="app-container">
      <!-- 自定义组件，标题 -->
      <PageTitle :show-before="true">
        <template v-slot:before>
          <h2>公告管理</h2>
        </template>
      </PageTitle>
      <el-row
        :gutter="10"
        type="flex"
        justify="space-between"
        style="margin-top: 20px"
      >
        <el-col :span="8">
          <el-select placeholder="不限显示状态">
            <el-option
              v-for="item in showStatus"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="6">
          <el-row type="flex">
            <el-col :span="6">
              <el-select placeholder="标题">
                <el-option
                  v-for="item in titleOptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-col>
            <el-row type="flex">
              <el-input placeholder="请输入搜索内容"></el-input>
              <el-button type="primary">
                <i class="el-icon-search"></i>
              </el-button>
            </el-row>
          </el-row>
        </el-col>
      </el-row>
      <!-- 数据表 -->
      <el-table
        v-loading="downloadLoading"
        ooltip-effect="dark"
        :data="list"
        max-height="500px"
        style="margin-top: 20px"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" fixed />
        <el-table-column label="ID" align="center" width="50" prop="id" fixed />
        <el-table-column
          label="标题"
          align="center"
          prop="title"
          width="350"
          fixed
        >
          <template slot-scope="scope">
            <el-link type="primary">{{ scope.row.title }}</el-link>
          </template>
        </el-table-column>
        <el-table-column
          label="排序"
          align="center"
          prop="source"
          width="130"
          fixed
        />
        <el-table-column label="点击" align="center" prop="click" width="180" />
        <el-table-column label="添加日期" align="center" prop="addtime">
          <template slot-scope="scope">
            <span>
              <i class="el-icon-time"></i>
              {{ scope.row.addtime }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          label="是否显示"
          align="center"
          prop="practice_sum"
          width="120"
        >
          <template>
            <el-switch
              v-model="model"
              active-color="#13ce66"
              inactive-color="#ff4949"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="prop"
          label="操作"
        >
          <template>
            <el-button type="primary" size="small" @click="editNotice"
              >编辑</el-button
            >
            <el-button type="danger" size="small" @click="delBtn"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-row :gutter="10" style="margin-top: 20px">
        <el-col :span="8">
          <el-button type="primary" size="small" @click="addNotice"
            >添加公告</el-button
          >
          <el-button type="primary" size="small" @click="showStateDialog = true"
            >显示状态</el-button
          >
          <el-button type="danger" size="small">删除所选</el-button>
        </el-col>
        <el-col :span="16">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage4"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="255"
            style="text-align: right"
          >
          </el-pagination>
        </el-col>
      </el-row>
    </div>
    <el-dialog
      title="将显示状态设置为"
      :visible.sync="showStateDialog"
      width="25%"
    >
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="显示状态">
          <el-radio v-model="radio" label="label">显示</el-radio>
          <el-radio v-model="radio" label="label">隐藏</el-radio>
        </el-form-item>
        <el-form-item label="">
          <el-row :gutter="10" type="flex" justify="end">
            <el-button @click="showStateDialog=false">取消</el-button>
            <el-button type="primary">确定</el-button>
          </el-row>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      model: true,
      editDialog: false,
      showStateDialog: false,
      list: [
        {
          id: 1,
          title: "公测版，欢迎测试，即将上线，敬请期待",
          content: "&lt;p &gt;北仑人才频道即将上线，公测中 &lt;\/p &gt;",
          attach: "[]",
          is_display: 1,
          link_url: "",
          seo_keywords: "",
          seo_description: "",
          click: 11,
          addtime: 1708158573,
          sort_id: 0,
          source: 0,
          source_reprint: "",
          link: "http:\/\/hr.blwang.com\/notice\/1.html",
          display: true,
        },
      ],
      platform: [
        { id: 1, name: "不限平台" },
        { id: 2, name: "APP" },
        { id: 3, name: "触屏端" },
        { id: 4, name: "微信小程序" },
        { id: 5, name: "pc端" },
      ],
      adPlatform: [{ id: 1, name: "不限广告位" }],
      showStatus: [
        { id: 1, name: "不限显示状态" },
        { id: 2, name: "显示" },
        { id: 3, name: "隐藏" },
      ],
      becomeTime: [
        { id: 1, name: "不限到期时间" },
        { id: 2, name: "已到期" },
        { id: 3, name: "三天内" },
        { id: 4, name: "一周内" },
      ],
      titleOptions: [
        { id: 1, name: "标题" },
        { id: 2, name: "广告ID" },
      ],
    };
  },
  methods: {
    // 添加公告
    addNotice() {
      this.$router.push({
        name: "addNotice",
      });
    },
    // 编辑公告
    editNotice() {
      this.$router.push({
        name: "editNotice",
      });
    },
    delBtn() {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style lang="scss" scoped></style>
